package flexGraphDemo
{
    import com.roundarch.adapt.utils.dates.DateUtil;
    import com.roundarch.flex.controls.graphControlInterfaces.IInterval;
    import com.roundarch.flex.controls.graphControlInterfaces.IIntervalToStringGenerator;

    import flash.events.Event;
    import flash.events.EventDispatcher;

    /**
     *
     * @author Josh
     */
    public class DSRFDateStringGenerator extends EventDispatcher implements IIntervalToStringGenerator
    {
        //---------------------------------------------------------------------
        //
        //  Properties
        //
        //---------------------------------------------------------------------
        //-----------------------------
        // format
        //-----------------------------
        /**
         * @private
         */
        protected var _format : Number = 0;

        [Bindable("formatChanged")]
        /**
         *
         *
         * @default 0
         */
        public function get format() : Number
        {
            return _format;
        }

        /**
         * @private
         */
        public function set format(value : Number) : void
        {
            if (value == _format)
            {
                return;
            }

            _format = value;

            dispatchEvent(new Event("formatChanged"));
        }

        //---------------------------------------------------------------------
        //
        //  Constructor
        //
        //---------------------------------------------------------------------
        /**
         *  Constructor
         */
        public function DSRFDateStringGenerator()
        {
        }

        //---------------------------------------------------------------------
        //
        //  Methods
        //
        //---------------------------------------------------------------------
        public function intervalToString(interval : IInterval, maxLength : int = -1) : String
        {
            return DateUtil.format(new Date(interval.start), format).dateString;
        }
    }
}
